﻿using System;
using System.Collections.Generic;

namespace VirtuosoDal.Entities
{
    public class Event
    {
        private string _uri;
        public string Uri
        {
            get
            {
                return _uri;
            }
            set
            {
                _uri = value;

                string[] uriParts = value.Split('/');
                _id = Convert.ToInt32(uriParts[uriParts.Length - 1]);
            }
        }

        private int _id;
        public int Id
        {
            get
            {
                return _id;
            }
        }

        /// <summary>
        /// UTC datetime of event creation
        /// </summary>
        public DateTime CreationDateTime { get; set; }
        public string Creator { get; set; }
        /// <summary>
        /// UTC datetime of event creation
        /// </summary>
        public DateTime LastEditingDateTime { get; set; }

        public string Title { get; set; }
        public string Description { get; set; }

        /// <summary>
        /// Event start datetime with local timezone
        /// </summary>
        public DateTimeOffset StartDateTimeOffset { get; set; }
        /// <summary>
        /// Event end datetime with local timezone
        /// </summary>
        public DateTimeOffset? EndDateTimeOffset { get; set; }

        public string Type { get; set; }
        public List<string> Categories { get; set; }
        public Dictionary<string, List<string>> AdditionalPropertiesWithValues { get; set; }

        public string CityUri { get; set; }
        public string CityName { get; set; }
        public string CountryName { get; set; }

        private string _placeUri;
        public string PlaceUri
        {
            get
            {
                return _placeUri;
            }
            set
            {
                _placeUri = value;

                if (!String.IsNullOrEmpty(_placeUri) && !String.IsNullOrEmpty(_placeName))
                    _placeIsSet = true;
                else
                    _placeIsSet = false;
            }
        }

        private string _placeName;
        public string PlaceName
        {
            get
            {
                return _placeName;
            }
            set
            {
                _placeName = value;

                //ToDo: Remove copypaste from PlaceUri
                if (!String.IsNullOrEmpty(_placeUri) && !String.IsNullOrEmpty(_placeName))
                    _placeIsSet = true;
                else
                    _placeIsSet = false;
            }
        }

        private bool _placeIsSet;
        public bool PlaceIsSet
        {
            get
            {
                return _placeIsSet;
            }
        }

        public Event()
        {
            Categories = new List<string>();
            AdditionalPropertiesWithValues = new Dictionary<string, List<string>>();
        }

        public Event(string uri)
            : this()
        {
            Uri = uri;
        }
    }
}
